package com.yinhe.music.yhmusic.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.yinhe.music.yhmusic.album.list.AlbumFragment;
import com.yinhe.music.yhmusic.constants.IConstants;
import com.yinhe.music.yhmusic.instrument.InstrumentBean;
import com.yinhe.music.yhmusic.music.list.MusicListFragment;
import com.yinhe.music.yhmusic.singer.SingerDetailFragment;
import com.yinhe.music.yhmusic.video.list.MvFragment;

import static com.yinhe.music.yhmusic.constants.IConstants.INSTRUMENT_ALBUM;
import static com.yinhe.music.yhmusic.constants.IConstants.INSTRUMENT_MV;

public class InstrumentInfoAdapter extends FragmentPagerAdapter {
    private InstrumentBean.InstrumentListBean mInstrumentInfo;

    public InstrumentInfoAdapter(FragmentManager fm, InstrumentBean.InstrumentListBean info) {
        super(fm);
        mInstrumentInfo = info;
    }

    public void update(InstrumentBean.InstrumentListBean info) {
        mInstrumentInfo = info;
        notifyDataSetChanged();
    }

    @Override
    public Fragment getItem(int position) {
        Fragment fragment = null;
        switch (position) {
            case 0:
                fragment = MusicListFragment.newInstance(IConstants.INSTRUMENT_MUSIC_LIST, mInstrumentInfo.getInstrumentId(), null, mInstrumentInfo.getSongNum());
                break;
            case 1:
                fragment = AlbumFragment.newInstance(INSTRUMENT_ALBUM, mInstrumentInfo.getInstrumentId(), null);
                break;
            case 2:
                fragment = MvFragment.newInstance(INSTRUMENT_MV, mInstrumentInfo.getInstrumentId());
                break;
            case 3:
                fragment = SingerDetailFragment.newInstance(mInstrumentInfo.getIntro(),IConstants.INSTRUMENT_DETAIL);
                break;
        }
        return fragment;
    }

    @Override
    public int getCount() {
        return 4;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                return "单曲" + "(" + mInstrumentInfo.getSongNum() + ")";
            case 1:
                return "专辑" + "(" + mInstrumentInfo.getAlbumNum() + ")";
            case 2:
                return "MV" + "(" + mInstrumentInfo.getMovieNum() + ")";
            case 3:
                return "详情";
            default:
                break;
        }
        return null;
    }
}
